<?php
/**
 * CreateUser: zlh
 * CreateTime: 2022/4/24 14:23
 * Remark:
 */

namespace App\Http\Controllers\Auth;

use App\Consts\ResponseConsts\ResponseStatusConsts;
use App\Func\ResponseFunc;
use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\AddAuthsRolePost;
use App\Service\Auth\AuthRoleService;

class AuthRoleController extends Controller
{
    private AuthRoleService $_authRoleService;

    public function __construct()
    {
        $this->middleware(
            [
                'authRoleLeg'
            ]
        );
        $this->_authRoleService = new AuthRoleService();
    }

    public function addRoleAuthsByRole(AddAuthsRolePost $rolePost): \Illuminate\Http\JsonResponse
    {
        $auths = $rolePost['auths'];
        $roleId = $rolePost['role_id'];
        return ResponseFunc::returnJson(
            'ok',
            $this->_authRoleService->addRoleAuthByRole($auths,$roleId),
            '绑定角色权限成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS
        );
    }

    /**
     * @param $roleId
     * @return \Illuminate\Http\JsonResponse
     */
    public function getRoleAuthInfo($roleId): \Illuminate\Http\JsonResponse
    {
        return ResponseFunc::returnJson(
            'ok',
            $this->_authRoleService->getRoleAuthInfo($roleId),
            '获取权限菜单成功',
            ResponseStatusConsts::OK_200_RESPONSE_STATUS
        );
    }
}